﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DaInterFace;
using DaInterFace.PDA;

namespace P03
{
    /// <summary>
    /// 袋装记录信息
    /// </summary>
    public class A01 : IPDAChild
    {
        public void Code(IPDA handler, CodeResult CR, PDACodeUser user, String parameter)
        {
            P02A01 P = (P02A01)handler.SerialApi.Deserialize(typeof(P02A01), parameter, CR.SerialType);

            try
            {
                SqlParameter[] sps = new SqlParameter[2];
                sps[0] = new SqlParameter("@FID", SqlDbType.NChar, 50);
                sps[1] = new SqlParameter("@Note", SqlDbType.NChar, 100);
                sps[0].Value = P.FID;
                sps[1].Value = String.Format("生产线：{0}-{1};当前袋数：{2};总袋数：{3};", P.id, P.line, P.qty.ToString(), P.sum.ToString());

                String sql = String.Format("UPDATE KEW_SalesInfo SET FNOTE2='{0}' WHERE FID={1}", sps[0].Value, sps[1].Value);
                sql += " EXEC KEW_SALES_LOG_INSERT @FID,@Note";
                Recordset rs = handler.Data.ExeProcedure(P.AccountNo, sql, sps);

                if (rs.Enable)
                {
                    CR.Result = EnumResult.Normal;
                    CR.Message = "袋装信息记录成功";
                    handler.Message(MessageType.Note, String.Format("操作员{0}对单据{1}进行了袋装信息记录", user.UserName, P.FID));
                }
                else
                {
                    CR.Result = EnumResult.Error;

                }

                handler.Message(MessageType.Note, CR.Message);
            }
            catch (Exception ex)
            {
                CR.Result = EnumResult.Error;
                CR.Message = ex.Message;
                handler.Message(MessageType.Error, String.Format("发生错误:{0}", ex.Message));
            }
        }

    }

    public class P02A01
    {
        public string FID;
        public string id;
        public String line;
        public ushort sum;
        public ushort qty;
        public string AccountNo;
    }
}
